using System;
using System.Xml.Schema;
using System.Xml.Serialization;
using flickr.api.communication;

namespace flickr.api
{
	public enum AuthenticationLevel
	{
		[XmlEnum]
        None, 
        [XmlEnum("read")]
        Read, 
        [XmlEnum("write")]
        Write, 
        [XmlEnum("delete")]
        Delete
	}

    [Serializable]
	public class Auth : FlickrObject
	{
        [XmlElement("token", Form=XmlSchemaForm.Unqualified)]
		public string Token;

        [XmlElement("perms", Form=XmlSchemaForm.Unqualified)]
		public AuthenticationLevel Permissions;

        [XmlElement("user", Form=XmlSchemaForm.Unqualified)]
		public AuthUser User;
        
        public Auth() : base() {}
        public Auth(FlickrConnection connection) : base(connection){}
        
        public Frob getFrob()
        {
            FlickrRequest request = CreateRequest();
            return Send(request).Frob;
        }
        
        public Auth checkToken(string token)
        {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.AuthToken, token);

            return Send(request).Auth;
        }
        
        public Auth getToken(string frob)
        {
            FlickrRequest request = CreateRequest();
            request.AddParameter(FlickrParameterType.Frob, frob);

            return Send(request).Auth;
        }

        public class AuthUser
        {
            [XmlAttribute("nsid")]
            public string ID;

            [XmlAttribute("username")]
            public string Name;

            [XmlAttribute("fullname")]
            public string Fullname;
        }
	}
}
